package com.example.demo.service.userservice.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.dao.user.UserMapper;
import com.example.demo.entity.user.User;
import com.example.demo.service.permissionservice.ITPermissionService;
import com.example.demo.service.userservice.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private ITPermissionService permissionService;


    @Override
    public Set<String> getRoles(String username) {
      //查询用户下面的角色信息
        return this.baseMapper.getRolesByUserName(username);
    }

    @Override
    public Set<String> getPermissions(String username) {
        return permissionService.getPermissionsByUserName(username);
    }

    @Override
    public User getByUsername(String username) {
        LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(User::getUsername,username);
        return this.baseMapper.selectOne(queryWrapper);
    }
}
